﻿@using ECGadmin.Common
@using ECGadmin.WebUI.CustomHelpers
@using ECGadmin.WebUI.Models
@model ConfigDto
@{
    ViewBag.Title = "Chỉnh sửa thông tin website";
    Layout = "~/Views/Shared/_layout.cshtml";
}

<nav>
    <div id="jCrumbs" class="breadCrumb module">
        <ul>
            <li><a href="@Url.Action("Index", "Home")"><i class="bootstrap icon-home"></i></a></li>
            <li><a href="@Url.Action("Index", "Config")">Thông tin website</a> </li>
            <li><a href="javascript:void(0);">Chỉnh sửa thông tin website</a></li>
        </ul>
    </div>
</nav>

<div class="toolBox">
    @Html.ToolBox(new List<object> { new Edit { ClassCss = "Edit", ActionName = "Javascript:void(0)" } ,
    new Back{ClassCss = "Back",ActionName = @Url.Action("Index","Config") } })
</div>

@using (Html.BeginForm("Edit", "Config", FormMethod.Post))
{
    @Html.HiddenFor(m => m.ConfigId)
    <div class="box-Info">
        <div class="Info-header">
            <span>Thêm vị trí mới</span>
        </div>

        <div class="Info-body ib-infopro">
            <div>@Html.ValidationMessage("ErrorSummary")</div>
            <table cellpadding="0" cellspacing="0" width="100%" border="0" class="table-info">
                <tr>
                    <td class="tInfoLeft">
                        Key
                    </td>
                    <td class="tInfoRight">
                        @Html.TextBoxFor(m => m.Key)
                        @Html.ValidationMessageFor(m => m.Key)
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">
                        Mô tả
                    </td>
                    <td class="tInfoRight">
                        @Html.TextBoxFor(m => m.Description)
                        @Html.ValidationMessageFor(m => m.Description)
                    </td>
                </tr>
                <tr>
                    <td class="tInfoLeft">
                        Kiểu giá trị dữ liệu
                    </td>
                    <td class="tInfoRight">
                        @Html.DropDownListFor(m => m.Type, new SelectList(CommonHelpers.ConfigTypeValueList(), "ItemValue", "ItemText"))
                    </td>
                </tr>
                <tr class="hidden TextEditor">
                    <td class="tInfoLeft">
                        Giá trị
                    </td>
                    <td class="tInfoRight">
                        @Html.TextAreaFor(m => m.Value, new { @class = "ckIntro", rows = "50", cols = "60", id = "editor1",@style="width:99%!important;" })
                        @Html.ValidationMessageFor(m => m.Value)
                    </td>
                </tr>
                <tr class="hidden StaticHtml">
                    <td class="tInfoLeft">
                        Giá trị
                    </td>
                    <td class="tInfoRight">
                        @Html.TextAreaFor(m => m.Value, new { rows = "25", cols = "90",@style="width:99%!important;color:#800000;" })
                    </td>
                </tr>
                <tr class="hidden Text">
                    <td class="tInfoLeft">
                        Giá trị
                    </td>
                    <td class="tInfoRight">
                        @Html.TextBoxFor(m => m.Value)
                    </td>
                </tr>
            </table>
        </div>
    </div>
}

@section scripts
{
    @Scripts.Render("~/bundles/jqueryval")
    <script src="@Url.Content("~/Scripts/WYSIWYG/ckeditor/ckeditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/WYSIWYG/ckfinder/ckfinder.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var editor = CKEDITOR.replace('editor1');
        CKFinder.setupCKEditor(editor, '/Scripts/WYSIWYG/ckfinder/');
    </script>

    <script>
        SubmitFormUseToolBox($('ul li.Edit a'), $('form'));
        
        // Page loaded --------------------------------------------------------------------------------
        var value = $('#Type').val();
        switch (value) {
            case 'TextEditor':
                $('.TextEditor').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                $('.Text, .StaticHtml').hide().find('textarea').removeAttr('Id Name');
                $('.Text').find('input').removeAttr('Id Name');
                break;
            case 'StaticHtml':
                $('.StaticHtml').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                $('.Text, .TextEditor').hide().find('textarea').removeAttr('Id Name');
                $('.Text').find('input').removeAttr('Id Name');
                break;
            case 'Text':
                $('.Text').show().find('input').attr({ 'Id': 'Value', 'Name': 'Value' });
                $('.StaticHtml, .TextEditor').hide().find('textarea').removeAttr('Id Name'); break;
            default:
                $('.TextEditor').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                $('.Text, .StaticHtml').hide().find('textarea').removeAttr('Id Name'); $('.Text').find('input').removeAttr('Id Name'); break;
        }
        
        /*
            DropDownList Type change event ------------------------------------------------------------
        */
        $('#Type').change(function () {
            var val = $(this).val();
            switch (val) {
                case 'TextEditor':
                    $('.TextEditor').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                    $('.Text, .StaticHtml').hide().find('textarea').removeAttr('Id Name'); $('.Text').find('input').removeAttr('Id Name'); break;
                case 'StaticHtml':
                    $('.StaticHtml').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                    $('.Text, .TextEditor').hide().find('textarea').removeAttr('Id Name'); $('.Text').find('input').removeAttr('Id Name'); break;
                case 'Text':
                    $('.Text').show().find('input').attr({ 'Id': 'Value', 'Name': 'Value' });
                    $('.StaticHtml, .TextEditor').hide().find('textarea').removeAttr('Id Name'); break;
                default:
                    $('.TextEditor').show().find('textarea').attr({ 'Id': 'Value', 'Name': 'Value' });
                    $('.Text, .StaticHtml').hide().find('textarea').removeAttr('Id Name'); $('.Text').find('input').removeAttr('Id Name'); break;
            }
        });
    </script>
}

